[SQL]Summing a column while ignoring duplicate records(row_number())


SELECT custid, SUM(amount)
FROM (SELECT t.*,
             ROW_NUMBER() OVER (PARTITION BY custid, transid ORDER BY transid) AS seqnum
      FROM table_1 t
     ) t
WHERE seqnum = 1;
#SQL






你可能感興趣的文章

單元測試的藝術, 2/e (The Art of Unit Testing: with examples in C#,  2/e)

單元測試的藝術, 2/e (The Art of Unit Testing: with examples in C#, 2/e)

CSS-[pseudo-classes]-偽類家族

CSS-[pseudo-classes]-偽類家族

〈 C++學習日記 #1〉指標 Pointer (Part.1)

〈 C++學習日記 #1〉指標 Pointer (Part.1)






留言討論